<!-- 搜索项目 -->
<template>
  <h-select-input-popup
    ref="hSelectInputPopup"
    v-model="val"
    v-bind="$attrs"
    v-on="$listeners"
    :params="queryParams"
    :keywords.sync="keywords"
    :getList="getList"
    @getDetail="getDetail"
    :isMulti="muitFlag"
	searchPlaceholder="请输入合同名称"
    @change="$emit('change', $event)"
  >
    <template v-slot:default="{ item }">
      <view class="project-item">
        <view class="option">
          <view class="lf">合同编号</view>
          <view class="rl">{{ item.finalNo }}</view>
        </view>
        <view class="option">
          <view class="lf">合同名称</view>
          <view class="rl">{{ item.htmc }}</view>
        </view>
        <view class="option">
          <view class="lf">项目名称</view>
          <view class="rl">{{ item.xmmc_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">项目编号</view>
          <view class="rl">{{ item.xmbh }}</view>
        </view>
        <view class="option">
          <view class="lf">签订单位</view>
          <view class="rl">{{ item.qddw_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">经营团队</view>
          <view class="rl">{{ item.jytd_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">项目承接人</view>
          <view class="rl">{{ item.xmcjr_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">经办部门</view>
          <view class="rl">{{ item.proposerDeptId_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">经办人</view>
          <view class="rl">{{ item.handlerId_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">创建日期</view>
          <view class="rl">{{ item.createTime }}</view>
        </view>
      </view>
    </template>
  </h-select-input-popup>
</template>

<script>
import { erpOmcContractManagerFinalList } from '@/api/index.js'
import { erpOmcContractManagerFinalId, erpOmcContractManagerFinalIds } from '@/api/index.js'

export default {
  name: 'HSelectOilCardInputPopup',
  data() {
    return {
      getList: erpOmcContractManagerFinalList,
      params: {
        column: 'createTime',
        order: 'desc',
        pageNo: 1,
        pageSize: 10,
        sysOrgCode: '',
        field: 'id,,,finalNo,htmc,xmmc_dictText,xmbh,qddw_dictText,jytd_dictText,xmcjr_dictText,handlerDeptId_dictText,handlerId_dictText,createTime'
      },
      keywords: '',
    }
  },
  model: {
    prop: 'value',
    event: 'input',
  },
  props: {
    value: {
      type: [String, Number, Array],
      default: null,
    },
    showName: {
      type: [String, Number],
      default: null,
    },
    htlx: {
      type: [String, Number],
      default: null,
    },
    status: {
      type: [String, Number],
      default: '2,3',
    },
    projectId: {
      type: [String, Number],
      default: null,
    },
	isCategoryType: {
      type: [String, Number],
      default: null,
    },
	jytd: {
      type: [String, Number],
      default: null,
    },
	signUnit: {
      type: [String, Number],
      default: null,
    },
	title: {
      type: String,
      default: '',
    },
    muitFlag: {
      type: Boolean,
      default: false,
    },
  },
  computed: {
    val: {
      get() {
        return this.value
      },
      set() {
        this.$emit('input', this.value)
      },
    },
    queryParams() {
      const params = {
        ...this.params,
      }
      if (this.keywords) {
        params.htmc = '*' + this.keywords + '*'
      }
      // if (this.showName) {
      //   params.showName = this.showName
      // }
      if (this.htlx) {
        params.htlx = this.htlx
      }
      if (this.status) {
        params.status = this.status
      }
      if (this.projectId) {
        params.xmmc = this.projectId
      }
	  if (this.isCategoryType !== null) {
        params.isCategoryType = this.isCategoryType
      }
      if (this.jytd) {
        params.jytd = this.jytd
      }
      if (this.signUnit) {
        params.qddw = this.signUnit
      }
      return params
    },
  },
  methods: {
    // 获取详情
    getDetail(value) {
      if (this.muitFlag) {
        erpOmcContractManagerFinalIds({ ids: value }).then((res) => {
          if (res.success) {
            const contractName = res.result.map(i => i.htmc).join(',')
            this.$refs.hSelectInputPopup.title = contractName
            this.$emit('update:contact-name', contractName)
            this.$emit('select', {
              data: res.result,
              id: value,
            })
          }
        })
      } else {
        erpOmcContractManagerFinalId({ id: value }).then((res) => {
          if (res.success) {
            this.$refs.hSelectInputPopup.title = res.result.htmc
            this.$emit('update:contact-name', res.result.htmc)
            this.$emit('select', {
              data: res.result,
              id: value,
            })
          }
        })
      }
    },
  },
}
</script>

<style lang="scss" scoped>

// 按钮
.btn {
  position: fixed;
  bottom: 20rpx;
  width: 95%;
}
</style>
